

from tkinter import *


root=Tk()

w = Canvas(root,width=500,height=300,background="#eee")

w.pack()


l1= w.create_line(0,50,200,50,
fill="yellow",width=5)

l2= w.create_line(100,0,100,100,
fill="red",dash=(4,4),
width=5)

r1=w.create_rectangle(50,25,150,75,fill="blue")
r2=w.create_rectangle(100,25,200,75,
fill="grey")

w.create_text(100,50,text="我爱你")

# 绘制椭圆，用长方形来限定
w.create_oval(140,140,160,160,fill="pink")

import math as m

center_x =250
center_y = 150

r=50

points=[

    # 左上点
    center_x-int(r*m.sin(2*m.pi/5)),
    center_y-int(r*m.cos(2*m.pi/5)),

    # 右上点
    center_x+int(r*m.sin(2*m.pi/5)),
    center_y-int(r*m.cos(2*m.pi/5)),

    # 左下点
    center_x-int(r*m.sin(m.pi/5)),
    center_y+int(r*m.cos(m.pi/5)),

    # 顶点
    center_x,
    center_y-r,

    # 右下点
    center_x+int(r*m.sin(m.pi/5)),
    center_y+int(r*m.cos(m.pi/5)),

]

# 多边形,多个点连起来
w.create_polygon(points,
    outline="green",
    fill="yellow")

# 修改

# 移动新的位置
w.coords(l1,0,25,100,25)

# 设置选项
w.itemconfig(r1,fill="black")

# w.move

w.delete(l2)


# 显示文本


Button(root,
text="删除",
command=(lambda x=ALL:w.delete(x))).pack()



mainloop()